import {Route,Switch,Redirect} from "react-router-dom"
import {Suspense} from "react"
let RouterView = (props)=>{
    console.log(props);
    let {RouterList} = props
    let routerlist = RouterList.filter(item=>!item.to)
    let redireect = RouterList.filter(item=>item.to)[0]
    return (
        <Suspense fallback={<div>...loading</div>}>
            <Switch>
                {
                    routerlist&&routerlist.length?routerlist.map((item,index)=>{
                        return <Route path={item.path} key={index} render={(routerProps)=>{
                                if (item.children) {
                                    return <item.component {...routerProps} child={item.children}></item.component>
                                }
                                return <item.component {...routerProps}></item.component>
                        }}>
                        </Route>
                    }):"暂无路由"
                }
                {
                    redireect?<Redirect to={redireect.to} from={redireect.from}></Redirect>:"暂无重定向"
                }

            </Switch>
        </Suspense>
    )
}
export default RouterView